package cn.com.zsw.gblog.client;

import cn.com.zsw.gblog.client.dto.GetUsrInfoRes;
import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.DataVariable;
import com.dtflys.forest.annotation.Request;
import org.springframework.stereotype.Component;

/**
 * @Author ：shiwangzhou
 * @Date ：Created in 2020-09-17 15:24
 * @Description： 调用QQ
 */
@Component
@BaseRequest(baseURL = "https://graph.qq.com", interceptor = ForestInterceptor.class)
public interface QqOauthClient {

    /**
     * desc: accessToken 获取用户openId
     *
     * @return java.lang.String
     * @author: shiwangZhou
     * @date: 2020-09-17 15:29
     * @param: accessToken accessToken
     */
    @Request(url = "/oauth2.0/me?access_token=${accessToken}")
    String getOpenId(@DataVariable("accessToken") String accessToken);

    /**
     * desc: 根据token,应用id和用户的openid虎丘用户信息
     *
     * @return java.lang.String
     * @author: shiwangZhou
     * @date: 2020-09-17 16:18
     * @param: accessToken  accessToken
     * @param: appId  应用ID
     * @param: openId 用户的openId
     */

    @Request(url = "/user/get_user_info?access_token=${accessToken}&oauth_consumer_key=${appId}" +
            "&openid=${openId}", dataType = "json")
    GetUsrInfoRes getUserInfo(@DataVariable("accessToken") String accessToken, @DataVariable("appId") String appId,
                              @DataVariable("openId") String openId);

    /**
     * desc: 通过Authorization Code获取Access Token
     *
     * @return java.lang.String  格式如下:access_token=FE8D878C863F7F8C8379033F8AF17FA2&expires_in=7776000
     * &refresh_token=B1AF324C4CC7B1112960A661EC66D279
     * @author: shiwangZhou
     * @date: 2020-09-21 19:56
     * @param: clientId 申请QQ登录成功后，分配给网站的appid。
     * @param: clientSecret 申请QQ登录成功后，分配给网站的appkey。
     * @param: code 上一步返回的authorization code。
     * @param: redirectUri 与上面一步中传入的redirect_uri保持一致。
     */

    @Request(url = "/oauth2.0/token?grant_type=authorization_code&client_id=${clientId}" +
            "&client_secret=${clientSecret}&code=${code}&redirect_uri=${redirectUri}", dataType = "json")
    String getAccessTokenByCode(@DataVariable("clientId") String clientId, @DataVariable("clientSecret") String clientSecret,
                                @DataVariable("code") String code, @DataVariable("redirectUri") String redirectUri);


}
